package com.pickgliss.effect
{
	import flash.display.DisplayObject;
	import flash.utils.Dictionary;

	public final class EffectManager
	{
		/**
		 *创建按钮光效的工厂
		 */
		private static var _instance:EffectManager;
		private var _effects:Dictionary;

		public static function get Instance():EffectManager
		{
			if (_instance == null)
			{
				_instance=new EffectManager();
			}
			return _instance;
		}

		private var _effectIDCounter:int=0;

		public function getEffectID():int
		{
			return _effectIDCounter++;
		}

		public function EffectManager()
		{
			_effects=new Dictionary();
		}
		/**
		 * 创建光效
		 * @param type
		 * @param target
		 * @param args
		 * @return 
		 * 
		 */		
		public function creatEffect(type:int, target:DisplayObject, ... args):IEffect
		{
			var effect:IEffect=creatEffectByEffectType(type);
			effect.initEffect(target, args);
			_effects[effect.id]=effect;
			return effect
		}

		/** 取得Effect的Target */
		public function getEffectByTarget($target:DisplayObject):IEffect
		{
			for each (var effect:IEffect in _effects)
			{
				if ($target == effect.target)
				{
					return effect
				}
			}
			return null;
		}
		/**
		 * 移除光效
		 */		
		public function removeEffect(effect:IEffect):void
		{
			effect.dispose();
			delete _effects[effect.id];
		}

		public function creatEffectByEffectType(type:int):IEffect
		{
			var effect:IEffect;
			switch (type)
			{
				case EffectTypes.ADD_MOVIE_EFFECT:
					effect=new AddMovieEffect(getEffectID());
					break;
				case EffectTypes.SHINER_ANIMATION:
					effect=new ShinerAnimation(getEffectID());
					break;
				case EffectTypes.ALPHA_SHINER_ANIMATION:
					effect=new AlphaShinerAnimation(getEffectID());
					break;
				case EffectTypes.Linear_SHINER_ANIMATION:
					effect=new LinearShinerAnimation(getEffectID());
					break;
			}
			return effect;
		}
	}
}